function TreeNode(x) {
    this.val = x;
    this.left = null;
    this.right = null;
}
function Serialize(pRoot)
{
    // write code here
    let vals = []
    function encode(cur){
      if(cur === null){
        vals.push('#')
      }else{
        vals.push(cur.val.toString())
        encode(cur.left)
        encode(cur.right)
      }
    }
    encode(pRoot)
    return vals.join(',')
}
function Deserialize(s)
{
    // write code here
    let vals = s.split(',')
    let i = 0
    function decode(){
      let val = vals[i]
      i++
      if(val === '#'){
        return null
      }else{
        let cur = new TreeNode(parseInt(val))
        cur.left = decode()
        cur.right = decode()
        return cur
      }
    }
    return decode()
}
module.exports = {
    Serialize : Serialize,
    Deserialize : Deserialize
};